var path = require('path');
var os = require('os');
var ifaces = os.networkInterfaces();
var fs = require('fs');

//微信公众号配置文件
var hema = {
    token: '_cqch',
    appid: 'wxbd8a3bff42f9886c',
    appsecret: '5fdcb2db20bb2c95b1a8a5cba3325ebf',
    encodingAESKey: 'aPvwHGlUuo47ZE8akmhXp71uWbdmXlSbT3ErowqflBn'
}

var cqch = {
    token: '_cqch',
    appid: 'wxbd8a3bff42f9886c',
    appsecret: '5fdcb2db20bb2c95b1a8a5cba3325ebf',
    encodingAESKey: 'aPvwHGlUuo47ZE8akmhXp71uWbdmXlSbT3ErowqflBn'
}

// var wxConfig = hema;

var static_dir = './public'
var version = '1.0.0'
var config = {
    // 静态资源映射文件
  	mapJson:   path.join(static_dir,'/dist/1.0.0/map.json'),
  	mapDevJson:   path.join(static_dir,'/dist/1.0.0/dev/map.json'),

    // 演示文件列表，ly demo/dev/pro启动http服务后，在浏览器端后缀demoindex
    demoindex: path.join(static_dir,'/dist/1.0.0/html/demoindex.html'),

    //本地上传路径
    upload: path.join(static_dir,'/dist/'),
    upload_root: path.join(static_dir,'/dist/uploader'),
    // 阿里云图片路径
    goods_img: 'http://jh-ljs-goods.oss-cn-shenzhen.aliyuncs.com/',     //商品
    account_img:'http://jh-ljs-account.oss-cn-shenzhen.aliyuncs.com/',  //用户

    //静态资源路径
    static: {
		dft:  path.join(static_dir,'/dist/1.0.0/'),
		html: path.join(static_dir,'/dist/1.0.0/html'),
		js:   path.join(static_dir,'/dist/1.0.0/js'),
		css:  path.join(static_dir,'/dist/1.0.0/css'),
		img:  path.join(static_dir,'/dist/1.0.0/images'),
        test: {
            dft:  path.join(static_dir,'/dist/1.0.0/dev'),
            html: path.join(static_dir,'/dist/1.0.0/dev/html'),
            js:   path.join(static_dir,'/dist/1.0.0/dev/js'),
            css:  path.join(static_dir,'/dist/1.0.0/dev/css'),
            img:  path.join(static_dir,'/dist/1.0.0/dev/images')
        }
  	},

    root: 'app',    //dev 或者 pro默认首页

    // apiip: "http://dev.dabai360.com/",
    // apiip: "http://10.170.139.181/",
    apiip: "http://im.dabai360.com/",
    port: "imapi/",

    //微信
    weixin: hema,

    domain: 'agzgz.com',
    domaintest: 'test.agzgz.com',

    auth: {
        github:{
            clientID: 'd65a863ee074f62231c5',
            clientSecret: '9f4a6a2f93c7c23405378c70bb2ae1c618734985',
            callbackURL: 'http://www.agzgz.com/github/callback',
            successUrl: '/dbdemo',
            userKey: 'githubuser',    //save this key to session
            headers: {"user-agent": "love_gz"}
        }
    },

    mongo: {
        url: "mongodb://58.96.191.90:27017/fkp",
        options: {
            db: { native_parser: true },
            server: { poolSize: 3 },
            replset: { rs_name: 'myReplicaSetName' },
            user: 'fkp',
            pass: 'a123456'
        },
        pageSize: 20
    },

    // test: {
    //     weixin: cqch,
    //     domain: 'test.agzgz.com',
    //     apiip: "http://functest.dabai360.com/",
    //     port: "imapi/",
    //     auth: {
    //         github:{
    //             clientID: 'b1ba9181f8928e4cbfa2',
    //             clientSecret: 'cb598749e899bc20514a4b9f583974fd13457550',
    //             callbackURL: 'http://localhost:3000/github/callback',
    //             successUrl: '/dbdemo',
    //             userKey: 'githubuser',    //save this key to session
    //             headers: {"user-agent": "bendi"}
    //         }
    //     },
    //     mongo: {
    //         url: "mongodb://58.96.191.90:27017/fkp",
    //         options: {
    //             db: { native_parser: true },
    //             server: { poolSize: 3 },
    //             replset: { rs_name: 'myReplicaSetName' },
    //             user: 'fkp',
    //             pass: 'a123456'
    //         },
    //         pageSize: 20
    //     }
    // }
}

function _config(target){
    var _cfg = config;

    if (target && typeof target!=='string'){
        target = false;
    }

    if (target && fs.existsSync('./configs/'+target+'.js')){
        _cfg = require('./configs/'+target+'.js');
        _cfg = _.extend(config, _cfg);
    }


    return _cfg;
}

module.exports = _config
